package componentdependencycircle;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import componentdependencycircle.ComponentDependencyCircleMatch;
import componentdependencycircle.ComponentDependencyCircleMatcherFactory;
import componentdependencycircle.ComponentDependencyCircleMatcher;

public class ComponentDependencyCircleConstraint extends Constraint<ComponentDependencyCircleMatch> {

	private ComponentDependencyCircleMatcherFactory matcherFactory;

	public ComponentDependencyCircleConstraint() {
		matcherFactory = new ComponentDependencyCircleMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "Component $component.name$ is involved in a dependency circle.";
	}

	@Override
	public EObject getLocationObject(ComponentDependencyCircleMatch signature) {
		Object location = signature.get("component");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<ComponentDependencyCircleMatch, ComponentDependencyCircleMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
